const BaseService = require("../base");

class AttrsService extends BaseService {
  async getBaseSaleAttrList() {
    const ctx = this.ctx;
    const baseSaleAttrs = await ctx.model.Product.BaseSaleAttrs.find();
    return this.toId(baseSaleAttrs);
  }

  async getSpuSaleAttrList(spuId) {
    const ctx = this.ctx;
    const spu = await ctx.model.Product.Spu.findOne({ _id: spuId }).populate("spuSaleAttrList");
    return this.toId(spu.spuSaleAttrList);
  }

  async saveBaseSaleAttr(name) {
    const ctx = this.ctx;
    await ctx.model.Product.BaseSaleAttrs.create({ name });
    return null;
  }
}

module.exports = AttrsService;
